{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "cv2.imshow('src',img)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "# 原理：将原图片三个点映射到目标图片上（左上角，左下角，右上角）\n",
    "matSrc = np.float32([[0,0],[0,height-1],[width-1,0]])\n",
    "matDst = np.float32([[50,50],[300,height-200],[width-300,100]])\n",
    "# 通过仿射变换矩阵进行组合 参数1：描述（左上角，左下角，右上角） 参数2：描述在目标图像上新的位置\n",
    "matAffine = cv2.getAffineTransform(matSrc,matDst)\n",
    "dstImg = cv2.warpAffine(img,matAffine,(width,height))\n",
    "cv2.imshow('dstImg',dstImg)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
